package com.wwdx.service.impl;

import com.google.common.collect.Maps;
import com.wwdx.model.WxMenuTree;
import com.wwdx.service.WxMenuTreeServiceI;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author liguoliang
 */
@Service
public class WxMenuTreeServiceImpl extends BaseServiceImpl<WxMenuTree> implements WxMenuTreeServiceI{

    @Override
    public Long selectMenuCount(WxMenuTree model) {
        Map<String, Object> params = Maps.newHashMapWithExpectedSize(2);
        String hql = "select count(1) from WxMenuTree\t" + getParams(model, params);
        return count(hql,params);
    }

    private String getParams(WxMenuTree model, Map<String, Object> params) {
        StringBuilder sb = new StringBuilder("where 1=1\n");
        Long id = model.getId();
        params.put("pid",id == null ? 0L : id);
        sb.append("and pid=:pid\t");
        return sb.toString();
    }

    @Override
    public List<WxMenuTree> selectMenuList(WxMenuTree model) {
        Map<String, Object> params = Maps.newHashMapWithExpectedSize(2);
        String hql = "from WxMenuTree\t" + getParams(model, params) +"\torder by sort desc";
        return find(hql,params);
    }
}